<?
require_once("conn.php");
?>
<h3>รายการของส่งไม่ครบ</h3>
<table width="100%">
	<tr>
		<td>Barcode</td>
		<td>รายการสินค้า</td>
		<td>Product Name</td>
		<td>Amount</td>
		<td>รวมขาดส่ง</td>
		<td>รวมค้างส่ง</td>
		<td>Confirm Date</td>
		<td>&nbsp;</td>
	</tr>
	<?
		$sql = "SELECT a.id as id,barcode,th,mm,sendamount,realamount,DATEDIFF(DATE(now()),confirmDate) AS DiffDate,confirmDate FROM pch_accept_order_detail as a join product as b on a.item=b.id join pch_sendisland_detail as c on a.send_detail_id=c.id WHERE state='0' ORDER BY a.id;";
		$query = mysql_query($sql);
		if(mysql_num_rows($query) > 0){
			while($row = mysql_fetch_array($query)){
				$unfinished = $row["sendamount"] - $row["realamount"];
				if($unfinished < 0){
					$unfinished = "-";
				}

				if($row["DiffDate"] > 3){
					$diff = '<span align="center" style="font-weight:bold;color:red;">'.$row["DiffDate"].'</span>';
				}else{
					$diff = $row["DiffDate"];
				}
			?>
				<tr>
					<td><?=$row["barcode"]?></td>
					<td><?=$row["th"]?></td>
					<td><?=$row["mm"]?></td>
					<td><?=$row["sendamount"]?></td>
					<td><?=$unfinished?></td>
					<td><?=$diff?></td>
					<td><?=$row["confirmDate"]?></td>
					<td><a href="#" onclick="clearUnfinished('<?=$row["id"]?>')">Clear</a></td>
				</tr>
			<?
			}
		}else{
		?>
			<tr><td colspan="8">ไม่มีรายการค้างส่ง</td></tr>
		<?
		}
		?>
</table>